package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.qiniu.QiNiuConfig;
import com.atguigu.lease.common.result.Result;
import com.qiniu.common.QiniuException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Tag(name = "文件管理")
@RequestMapping("/admin/file")
@RestController
public class FileUploadController {

    @Autowired
    private QiNiuConfig qiNiuConfig;

    @Operation(summary = "上传文件")
    @PostMapping("upload")
    public Result<String> upload(@RequestParam MultipartFile file) throws IOException {
        String url = qiNiuConfig.upload(file);
        return Result.ok(url);
    }

    @Operation(summary = "删除文件")
    @PostMapping("delete")
    public Result<String> delete(@RequestParam String url) throws QiniuException {
        String delete = qiNiuConfig.delete(url);
        return Result.ok(delete);
    }
}
